<!DOCTYPE HTML>
<html>
<head>
	<meta http-equiv="PRAGMA" content="NO-CACHE">
	<meta http-equiv="CACHE-CONTROL" content="NO-CACHE">
	<meta http-equiv="X-UA-Compatible" content="IE=7,IE=9">
	<title>Rendering Rule</title>
	<link rel="stylesheet" type="text/css" href="../../../../js/dojo/dijit/themes/claro/claro.css">
  <link rel="stylesheet" type="text/css" href="../../../../js/esri/css/esri.css">
  <script type="text/javascript">
    var dojoConfig = {
      parseOnLoad:true,
      isDebug: true,
      packages: [
          {
            name: "esri",
            location: "../../../js/esri" 
          }
      ]
    };
  </script>   
  <script type="text/javascript" src="../../../dojo/dojo/dojo.js"></script>
	<script type="text/javascript">
		dojo.require("esri.dijit.RenderingRule");
		dojo.require("esri.map");
    dojo.require("esri.arcgis.utils");
		dojo.require("dojox.layout.ContentPane");
		dojo.require("dijit.form.DropDownButton");
		dojo.require("dijit.TooltipDialog");
		var map;
		var basemap;
		var myWidget;
		var urlerror=1;
    var seturl="http://imagery.arcgisonline.com/arcgis/rest/services/LandsatGLS/LandsatMaster/ImageServer";
 			var loading;
			//loading image. id
			function init() {
				dojo.byId("urlValue").value = seturl;
				map = new esri.Map("MapDiv");
				this.addLayerToMap();
				loading = dojo.byId("loadingImg");
				//loading image. id
				dojo.connect(map, "onUpdateStart", function() {
					esri.show(loading);
					map.disableMapNavigation();
					map.hideZoomSlider();
				});

				dojo.connect(map, "onUpdateEnd", function(error) {
					esri.hide(loading);
					map.enableMapNavigation();
					map.showZoomSlider();
				});
			}

			function failed(response) { {
					alert("Incorrect URL");
				}
			}

			function addLayerToMap() {
				var url = dojo.byId("urlValue").value;
				map.removeAllLayers();
				var newLayer = new esri.layers.ArcGISImageServiceLayer(url);
				map.addLayer(newLayer);
				if(myWidget == null) {
					myWidget = new esri.dijit.RenderingRule({
						layer : newLayer,
						map : map
					}, dojo.byId('nodeid'));
				} else {
					myWidget.set("layer", newLayer);
				}

				myWidget.startup();

				esri.request({
					url : url,
					content : {
						f : "json"
					},
					callbackParamName : "callback",
					load : dojo.hitch(this, zoomToLayerHandler)
				});
			}

			function zoomToLayerHandler(response, io) {
				var extent = new esri.geometry.Extent(response.extent);
				var geometryService = new esri.tasks.GeometryService("http://tasks.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer");
				var graphic = new esri.Graphic(extent);
				var outSR = map.spatialReference;

				geometryService.project([graphic.geometry], outSR, dojo.hitch(this, function(features) {
					map.setExtent(features[0]);
				}));
			}

			dojo.addOnLoad(init);
	</script>
</head>
<body class="claro">
  
  	<input id="urlValue" type="text" value="Enter URL" style="width:400px;"/>
  	<button id="button1" onclick="addLayerToMap()" >ADD</button>
  	<div data-dojo-type="dijit.form.DropDownButton" style="width:400px;" id="sfg">
      		<span>Renderer</span>
        <div id="tooltip" data-dojo-type="dijit.TooltipDialog">
     		<div id="nodeid"></div>
    	</div>
  	</div>	
  	<div id="MapDiv" data-dojo-type="dojox.layout.ContentPane" style="height:900px;width:100%;">
    <img id="loadingImg" src="../images/loading.gif" style="position:absolute; right:50%; top:50%; z-index:100;"/>
    </div>
</body>
</html>